﻿using System;
using System.Data;
using System.Data.SqlClient;
using System.Data.OleDb;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;

using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DAL;
using CommontLibrary;
using System.Xml;
using System.Xml.Xsl;
using System.IO;
using System.Text;

public partial class UserControl_Reports_loadReportCountDiemCC : System.Web.UI.UserControl
{
#region "Member variables"
   
    //DANguoidung objNguoidung;
    //DAHocVien objHocVien;
    //DAQuyen objQuyen;
    #endregion
#region "Events handle"
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            DataTable mydt = load_diem("19010101", "99990101");
            GridView1.DataSource = mydt.DefaultView;
            GridView1.DataBind();
        }
        //Label1.Text = DateTime.Now.AddDays(1).ToShortDateString();
    }
    
#endregion
    protected void Button1_Click(object sender, EventArgs e)
    {
        
        StringBuilder startdate, enddate;
        startdate= new StringBuilder (TextBox1.Text);
        enddate = new StringBuilder(TextBox2.Text);

        try
        {
            if (startdate[1] == '/')
            {
                startdate.Insert(0, "0");
            }

            if (enddate[1] == '/')
            {
                enddate.Insert(0, "0");
            }
            if (startdate[4] == '/')
            {
                startdate.Insert(3, "0");
            }
            if (enddate[4] == '/')
            {
                enddate.Insert(3, "0");
            }

            //Kiem tra ngay nhap rong
            string str_startdate = startdate.ToString().Trim();
            string str_enddate = enddate.ToString().Trim();
            if (str_startdate.Length == 0)
            {
                str_startdate = "19010101";
            }
            else
            {
                str_startdate = str_startdate.Substring(6, 4) + str_startdate.Substring(3, 2) + str_startdate.Substring(0, 2);
            }

            if (str_enddate == "")
            {
                str_enddate = "99990101";
            }
            else
            {
                str_enddate = str_enddate.Substring(6, 4) + str_enddate.Substring(3, 2) + str_enddate.Substring(0, 2);
            }
            
            DataTable mydt = load_diem(str_startdate, str_enddate);
            GridView1.DataSource = mydt.DefaultView;
            GridView1.DataBind();
      
            Label1.Text = str_startdate.ToString();
        }
        catch(Exception ex)
        {
            Label1.Text = "Nhap Sai Ngay:mm/dd/yyyy" + ex.Message;
        }
        
    }
    protected DataTable load_diem(string startdate, string enddate)
    {
        
        SqlConnection myconn = ConnectData.getConnection();
        SqlCommand mycomm = new SqlCommand("proc_contact_L2_ctv", myconn);
        mycomm.CommandType = CommandType.StoredProcedure;
        mycomm.Parameters.Add(new SqlParameter("@startdate",startdate));
        mycomm.Parameters.Add(new SqlParameter("@enddate", enddate));
        SqlDataAdapter myda = new SqlDataAdapter(mycomm);
        DataTable mydt = new DataTable();
        myda.Fill(mydt);        
        myconn.Close();
       // myconn.Dispose();
        return mydt;
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
       
        
    }
    
   
}
